//
//  UIBarButtonItem+category.swift
//  FirstSwiftProduct
//
//  Created by 范泽华 on 2017/10/10.
//  Copyright © 2017年 范泽华. All rights reserved.
//

import UIKit


extension UIBarButtonItem {
    /**
     *  创建一个item
     *
     *  @param target    点击item后调用哪个对象的方法
     *  @param action    点击item后调用target的哪个方法
     *  @param image     图片
     *  @param highImage 高亮的图片
     *
     *  @return 创建完的item
     */
    class func item_fzh_Create(target:Any, action:Selector, image:String,highImage:String) -> UIBarButtonItem {
        let btn = UIButton.init(type: UIButtonType.custom)
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        btn.setBackgroundImage(UIImage.init(named: image as String), for: UIControlState.normal)
        if (!highImage.isEmpty)  {
            btn.setBackgroundImage(UIImage.init(named: highImage), for: UIControlState.highlighted)
        }
        
        btn.sizeToFit();
        return UIBarButtonItem.init(customView: btn)
    }
}
